#include "plot.h"

Plot::Plot(void)
	: QwtPlot()
{
	m_canvas_color = Qt::black;

	m_canvas = new QwtPlotCanvas();
	m_canvas->setLineWidth(0);
	m_canvas->setFrameStyle(QFrame::Box | QFrame::Plain);
	m_canvas->setBorderRadius(0);
	m_canvas->setPalette(m_canvas_color);
	this->setCanvas(m_canvas);

	m_grid = new QwtPlotGrid();
	m_grid->enableXMin(true);
	m_grid->setMajorPen(Qt::gray, 0, Qt::DotLine);
	m_grid->setMinorPen(Qt::darkGray, 0, Qt::DotLine);

	/*
	m_legendItem = new QwtPlotLegendItem();
	QColor color(Qt::white);
	m_legendItem->setTextPen(color);
	m_legendItem->setMaxColumns(1);
	m_legendItem->setAlignment(Qt::Alignment(Qt::AlignRight | Qt::AlignTop));
	m_legendItem->setBackgroundMode(QwtPlotLegendItem::LegendBackground);
	m_legendItem->setBorderRadius(8);
	m_legendItem->setMargin(4);
	m_legendItem->setSpacing(2);
	m_legendItem->setItemMargin(0);
	m_legendItem->attach(this);
	*/

	m_panner = new QwtPlotPanner(this->canvas());

	/*
	m_marker = new QwtPlotMarker();
	m_marker->setLineStyle(QwtPlotMarker::VLine);
	m_marker->setLinePen(Qt::darkGreen, 1);
	m_marker->setXValue(50.0);
	m_marker->attach(this);
	*/

	/*
	m_d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, this->canvas());
	m_d_picker->setStateMachine(new QwtPickerDragPointMachine());
	m_d_picker->setRubberBandPen(QColor(Qt::white));
	m_d_picker->setRubberBand(QwtPicker::CrossRubberBand);
	m_d_picker->setTrackerPen(QColor(Qt::white));
	*/

	/*
	m_zoomer = new QwtPlotZoomer(QwtPlot::xBottom, QwtPlot::yLeft, this->canvas());
	m_zoomer->setRubberBand(QwtPicker::RectRubberBand);
	m_zoomer->setRubberBandPen(QColor(Qt::green));
	m_zoomer->setTrackerMode(QwtPicker::ActiveOnly);
	m_zoomer->setTrackerPen(QColor(Qt::white));
	*/

	m_plotMagnifier = new QwtPlotMagnifier(this->canvas());
}

Plot::~Plot(void)
{

}

void Plot::XscaleLock(bool on)
{
	m_plotMagnifier->setAxisEnabled(QwtPlot::xBottom, on);
}
void Plot::YscaleLock(bool on)
{
	m_plotMagnifier->setAxisEnabled(QwtPlot::yLeft, on);
}

void Plot::gridOnOff(bool on)
{
	if (on)
	{
		m_grid->attach(this);
	}
	else
	{
		m_grid->detach();
	}
	replot();
}

void Plot::setCanvasColor(QColor c)
{
	m_canvas_color = c;
	m_canvas->setPalette(m_canvas_color);
	replot();
}

QColor Plot::getCanvasColor(void)
{
	return m_canvas_color;
}